/**
 * \file
 *           tlmRmtCfgParaWeb.cpp
 * \brief
 *           Implements tlmRmtCfgParaWeb class for Telematics services
 *           this is the class of parameters for Web.
 *
 * \par Author (last changes):
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Project Leader:
 *          -
 * \par Responsible Developer:
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Architect:
 *          - Zhang Fa
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 *
 * \par Project:
 *      DPCA2
 *
 * \par SW-Component:
 *      Telematics
 *
 * \par SW-Package:
 *      Telematics
 *
 * \par SW-Module:
 *      Telematics Application
 *
 * \par SW-Architecture Specification:
 *      DPCA –TELEMATICS SW DD
 *      05b
 *
 * \par SW-Design Specification:
 *      DPCA –TELEMATICS SW DD
 *      05b
 *
 * \par SW-Test Case Specification:
 *
 * \par CM-Info:
 *
 * \note
 *      This is a note.
 *
 * \bug
 *      - there are no known bugs
 *
 * \par Module-History:
 *
 * \verbatim
 * Date                Author					Reason
 * 10 Dec 2013        Zeng Jie              Initial Creation
 * The latest entry at the head of the history list.
 * \endverbatim
 *
 * \par Copyright Notice:
 * Copyright (C) 2012 Continental Automotive Holdings Co., Ltd.
 * Alle Rechte vorbehalten. All Rights Reserved.\n
 * The reproduction, transmission or use of this document or its contents is
 * not permitted without express written authority.\n
 * Offenders will be liable for damages. All rights, including rights created
 * by patent grant or registration of a utility model or design, are reserved.
 *
 */
#include "stdafx.h"

#include "Telematics.h"
#include "teleLogTrace.h"
#include "string.h"
#include "tlmServiceFactory.h"
#include "tlmRmtCfgParaWeb.h"
//#[ ignore

//#]


/**
* \brief tlmRmtCfgParaWeb: this is constructor of tlmRmtCfgParaWeb class
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgParaWeb::tlmRmtCfgParaWeb() :tlmRmtCfgPara(TLM_RMT_CFG_PARA_WEB_ELEMENT_COUNT), mFreeSurfStatus(E_TLM_REMOTE_CONFIG_WEB_FREE_SURF_STATUS), mRmtHmiStatus(E_TLM_REMOTE_CONFIG_WEB_REMOTE_HMI_STATUS), mSpdThreshold(E_TLM_REMOTE_CONFIG_WEB_GEN_SPEED_THRESHOLD), mWebPortalStatus(E_TLM_REMOTE_CONFIG_WEB_WEB_PORTAL_STATUS), mWebPortalSubStatus(E_TLM_REMOTE_CONFIG_WEB_WEB_PROTAL_SUB_STATUS)  {
    
    //#[ operation tlmRmtCfgParaWeb()
    
    mEleParaList[0]=&mSpdThreshold;
    mEleParaList[1]=&mFreeSurfStatus;
    mEleParaList[2]=&mWebPortalStatus;
    mEleParaList[3]=&mWebPortalSubStatus;
    mEleParaList[4]=&mRmtHmiStatus;
	mSrvId=E_TLM_RMT_CFG_SERVICE_ID_WEB;
    	
    
    //#]
}

/**
* \brief ~tlmRmtCfgParaWeb: this is destructor of tlmRmtCfgParaWeb class
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgParaWeb::~tlmRmtCfgParaWeb() {
}

/**
* \brief GetItem : get the parameter element by it's code
*
* \note
*
* \param[in]
* - code : the code of parameters element
*
* \return
* - tlmRmtCfgElementPara*: pointer to parameter element
*
* DesignID: MRN_TLM-SRV_SW_DD_024
*/
tlmRmtCfgElementPara* tlmRmtCfgParaWeb::GetItem(uint8_t code) {
    //#[ operation GetItem(uint8_t)
    tlmRmtCfgElementPara * pItem=NIL;
    switch(code)
    {
    	case E_TLM_REMOTE_CONFIG_WEB_GEN_SPEED_THRESHOLD:  
        {
    		pItem = &mSpdThreshold;
    		break;
        }
    	case E_TLM_REMOTE_CONFIG_WEB_FREE_SURF_STATUS:   
        {
    		pItem = &mFreeSurfStatus;
    	 	break;  
        }
    	case E_TLM_REMOTE_CONFIG_WEB_WEB_PORTAL_STATUS:
        {
    		pItem = &mWebPortalStatus;
    	 	break; 
        }
    	case E_TLM_REMOTE_CONFIG_WEB_WEB_PROTAL_SUB_STATUS: 
        {
    		pItem = &mWebPortalSubStatus;
    	 	break;
        }
    	case E_TLM_REMOTE_CONFIG_WEB_REMOTE_HMI_STATUS:
        {
    		pItem = &mRmtHmiStatus;
    	 	break;
        }
    	default:
        {
            //LOG_PRINT(DPCA_TELE_MSGSRV_ERROR,"[TLM_MSGSRV]:<tlmRmtCfgParaWeb::%s> invalid para code[%d]\n", __FUNCTION__, code);

    		break;
        }
    }    
    
    return pItem;
    
    //#]
}

/**
* \brief Save: save web parameters into NVM
*              If any element is update, the all web parameters shall be saved.
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t: save status
*
* DesignID: MRN_TLM-SRV_SW_DD_025
*/
uint8_t tlmRmtCfgParaWeb::Save() {

    //#[ operation Save()
    BOOL isUpdated = FALSE; 
    S_TLM_REMOTE_CFG_WEB_DATA sWebData;   
    uint8_t status=0;
     
    //any item is updated, the total web parameters shall be save into NVM. 
    isUpdated = mSpdThreshold.IsUpdated() |
                mFreeSurfStatus.IsUpdated() |
                mWebPortalStatus.IsUpdated() |
                mWebPortalSubStatus.IsUpdated() |
                mRmtHmiStatus.IsUpdated(); 
                
    if(isUpdated)
    {//the parameters is udpated  
    	memset(&sWebData, 0, sizeof(sWebData));
    	sWebData.freeSurf = *(reinterpret_cast<bool_t *>(mFreeSurfStatus.GetValuePtr()));
    	sWebData.webPortal = *(reinterpret_cast<bool_t *>(mWebPortalStatus.GetValuePtr()));
    	sWebData.webPortalSubStatus = *(reinterpret_cast<bool_t *>(mWebPortalSubStatus.GetValuePtr()));
    	sWebData.rmtHmiStatus = *(reinterpret_cast<bool_t *>(mRmtHmiStatus.GetValuePtr()));
    	sWebData.speedThreshold = *(reinterpret_cast<uint8_t *>(mSpdThreshold.GetValuePtr()));
        
        
        status = tlmServiceFactory::GetInstance()->GetSaverInstance()->SaveParameters(ERG_DPCA_TLM_REMOTECFG_WEB,reinterpret_cast<uint8_t*>(&sWebData),sizeof(sWebData));
    }  
    
    return status;
    //#]
}

/*
tlmRmtCfgElementPara* tlmRmtCfgParaWeb::getMFreeSurfStatus() {
    return static_cast<tlmRmtCfgElementPara*>(&mFreeSurfStatus);
}

tlmRmtCfgElementPara* tlmRmtCfgParaWeb::getMRmtHmiStatus() {
    return static_cast<tlmRmtCfgElementPara*>(&mRmtHmiStatus);
}

tlmRmtCfgElementPara* tlmRmtCfgParaWeb::getMSpdThreshold() {
    return static_cast<tlmRmtCfgElementPara*>(&mSpdThreshold);
}

tlmRmtCfgElementPara* tlmRmtCfgParaWeb::getMWebPortalStatus() {
    return static_cast<tlmRmtCfgElementPara*>(&mWebPortalStatus);
}

tlmRmtCfgElementPara* tlmRmtCfgParaWeb::getMWebPortalSubStatus() {
    return static_cast<tlmRmtCfgElementPara*>(&mWebPortalSubStatus);
}
*/
